package com.gugee.ins.data.analysis.listener;

import com.gugee.ins.data.analysis.config.InsAnalysisConfig;
import com.gugee.ins.data.analysis.service.InsAnalysisLocationService;
import com.gugee.ins.data.common.consumer.AbstractGugeeConsumerHandler;
import com.gugee.ins.data.common.msg.InsBloggerMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * InsAnalysisLocation Listener
 *
 * @author Huangxin
 */
@Component
@Slf4j
public class InsAnalysisLocationListener {

    /**
     * InsAnalysisLocation Config
     */
    @Autowired
    private InsAnalysisConfig insAnalysisConfig;

    /**
     * InsAnalysisLocation Service
     */
    @Autowired
    private InsAnalysisLocationService insAnalysisLocationService;

    private InsAnalysisLocationHandler analysisHandler = new InsAnalysisLocationHandler();

    /**
     * 监听任务,完成头像分析
     * @param messages
     * @param ack
     */
    @KafkaListener(id="${kafka.consumer.group.insAnalysisLocation.id}",
            topics = {"${kafka.topics.insAnalysisLocation.online}","${kafka.topics.insAnalysisLocation.priority}"},
            containerFactory = "factoryInsAnalysisLocationAck")
    public void bloggerMainCollect(List<InsBloggerMessage> messages, Acknowledgment ack) {
        analysisHandler.handle("InsAnalysisLocation",messages, insAnalysisConfig.getAcceptInsAnalysisLocationMsgTimeMinRange(),ack);
    }

    class InsAnalysisLocationHandler extends AbstractGugeeConsumerHandler<InsBloggerMessage>{
        @Override
        public void dealMsg(List<InsBloggerMessage> messages) {
            insAnalysisLocationService.handleAnalysisLocation(messages);
        }
    }
}
